<template>
  <div class="app-container">
    <el-form
      ref="form"
      v-loading="formLoading"
      :data="form"
      element-loading-text="加载中..."
      :model="form"
      label-width="120px"
    >
      <el-input v-model="form.id" type="hidden"/>
      <el-form-item label="头像">
        <img :src="form.icon" width="60" height="60">
      </el-form-item>
      <el-form-item label="账号">
        <el-input v-model="form.userName" :disabled="true"/>
      </el-form-item>
      <el-form-item label="邮箱">
        <el-input v-model="form.email"/>
      </el-form-item>
      <el-form-item label="昵称">
        <el-input v-model="form.nickName"/>
      </el-form-item>
      <el-form-item label="备注">
        <el-input v-model="form.remark"/>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-input v-model="form.createTime" :disabled="true"/>
      </el-form-item>
      <el-form-item label="最后登录">
        <el-input v-model="form.updateTime" :disabled="true"/>
      </el-form-item>
      <el-form-item label="是否启用">
        <el-radio-group v-model="form.status">
          <el-radio :label="1">禁用</el-radio>
          <el-radio :label="0">启用</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  import { getInfo, update } from '@/api/profile'

  export default {
    name: "ProfileInfo",
    data() {
      return {
        form: {
          icon: '',
          userName: '',
          id: '',
          email: '',
          nickName: '',
          remark: '',
          createTime: '',
          updateTime: '',
          status: ''
        }
      }
    },

    created() {
      this.profileData()
    },
    methods: {
      profileData() {
        getInfo(this.$store.getters.name).then(response => {
          this.form = response.data

        })
      },
      onSubmit() {
        this.formLoading = true
        update(this.form).then(response => {
          this.formLoading = false
          this.$message({
            message: response.message,
            type: 'success'
          })
        }).catch(() => {
          this.formLoading = false
        })
      }
    }
  }
</script>

<style scoped>

</style>
